const app = getApp()
Component({
    externalClasses: ['i-class'],
    properties: { 
      pageid: {
        type: Number,
        observer: function(newVal, oldVal) {
          this.updateid()
        }
      }
    },
    behaviors: [
        module.exports = Behavior({
        attached: function() {
        var that=this
        wx.getSystemInfo({
          success: function(res) {
            wx.setStorageSync('SystemInfo',res)
          }
        });
        that.pagecontent(that.data.pageid);
        }
      })],
    data: {
      scrollTop:0
    }, 
 
    methods: {
      touchstart:function(e) {
        this.setData({
           scrollTop:e.detail.scrollTop
        })
      },
      changeshare:function(){ 
         this.triggerEvent ('changeshare',this.data.info.page.name)
      },
      pagecontent:function(id){
        var that=this
        wx.request({
          url: app.globalData.siteroot,
          data: {
            do:'index_pagedata',
            id:id,
            user_id:wx.getStorageSync('user_id')
          },
          success: function(res) {
              app.globalData.styles=res.data.info.styles.css
              app.globalData.all_data=res.data.info.all_data
              if(res.data.info.page.bg_img==''){
                that.setData({
                  pageStyle:"background-color: ".concat(res.data.info.page.bg_color)
                })
              }else{
                that.setData({
                  pageStyle:"background-image: url(".concat(res.data.info.page.bg_img)+");background-size: 100% 100%;background-color: ".concat(res.data.info.page.bg_color)
                })
              }
              that.setData({
                  info:res.data.info,
                  dataList:res.data.info.all_data
              })
              that.changeshare();
              for (var i = 0; i < res.data.info.all_data.length; i++) {
                 var type=res.data.info.all_data[i].type;
                 var styledata=res.data.info.all_data[i];
                 if(type==='diy_bargain'||type==='diy_group'||type==='diy_seckill'||type==='diy_integral')
                 {
                   app.globalData.module_activity=styledata;
                 }
                 if(type==='diy_audio')
                 {
                  app.globalData.module_audio=styledata;
                 }
                 if(type==='banner')
                 {
                  app.globalData.lunbo=styledata;
                 }
                 if(type==='navigation')
                 {
                  app.globalData.naviag=styledata;
                 }
                 if(type==='blankline')
                 {
                  app.globalData.lineplace=styledata;
                 }
                 if(type==='headline')
                 {
                  app.globalData.biaoti=styledata;
                 }
                 if(type==='articles1')
                 {
                  app.globalData.articles1=styledata;
                 }
                 if(type==='articles2')
                 {
                  app.globalData.articles2=styledata;
                 }
                 if(type==='image_group1')
                 {
                  app.globalData.imagegroup1=styledata;
                 }
                 if(type==='image_group2')
                 {
                  app.globalData.imagegroup2=styledata;
                 }
                 if(type==='diy_comment')
                 {
                  app.globalData.diycomment=styledata;
                 }
                 if(type==='block')
                 {
                  app.globalData.cblock=styledata;
                 }
                 if(type==='my_video')
                 {
                  app.globalData.videopart=styledata;  
                 }
                 if(type==='diy_search')
                 {
                  app.globalData.search=styledata; 
                 }
                 if(type=='diy_wx_advert'||type=='diy_qq_advert')
                 {
                  app.globalData.wxadvert=styledata; 
                 }
                 if(type=='gzh_concern')
                 {
                  app.globalData.official_account=styledata; 
                 }
                 if(type=='diy_form')
                 {
                  app.globalData.diyform=styledata; 
                 }
                 if(type=='diy_map')
                 {
                  app.globalData.diymap=styledata; 
                 }
                 if(type=='announcement')
                 {
                  app.globalData.announcement=styledata; 
                 }
                 if(type=='services1'||type=='services2')
                 {
                    app.globalData.services1=styledata; 
                    
                 }
                 if(type=='diy_editor')
                 {
                  app.globalData.module_editor=styledata; 
                 }
                 if(type==='diy_videolist_style1'||type==='diy_videolist_style2'||type==='diy_videolist_style3')
                 {
                  app.globalData.module_video_list=styledata;   
                 }
                 if(type==='diy_live_style1'||type==='diy_live_style2'||type==='diy_live_style3')
                 {
                  app.globalData.module_live_list=styledata;   
                 }
                 if(type==='diy_goods_style1'||type==='diy_goods_style2'||type==='diy_goods_style3')
                 {
                  app.globalData.module_good_list=styledata;   
                 }
                 if(type==='diy_coupon_style1'||type==='diy_coupon_style2')
                 {
                  app.globalData.module_coupon=styledata;   
                 }
                 if(type==='module_tabbar_list')
                 {
                  app.globalData.module_tabbar_list=styledata;   
                 }
              }
          }
        })
      },
      updateid:function(){
        this.pagecontent(this.data.pageid);
      }  
    }
});
